using System;
using System.ComponentModel;
using DevExpress.XtraEditors;

namespace Damar
{
	public partial class ProcessingXtraForm: XtraForm
	{        
        private Controller _controller;
        
        public Controller Controller { set { _controller = value; } }
        
        public ProcessingXtraForm()
		{
            InitializeComponent();
        }

        #region Event Handlers

        private void ProcessingXtraForm_Load(object sender, EventArgs e)
        {
            _controller.DocumentProcessing += DocumentProcessing;
            backgroundWorker.RunWorkerAsync();
        }

        private void DocumentProcessing(object sender, EventArgs e)
        {
            backgroundWorker.ReportProgress(0);
        }

        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            _controller.Import();
        }

        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            _controller.DocumentProcessing -= DocumentProcessing;
            Close();
        }

        private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBarControl.Properties.Maximum = _controller.DocumentCount;
            progressBarControl.Properties.Step = 1;
            progressBarControl.PerformStep();
            processingLabelControl.Text = "Processando documento: " + _controller.DocumentNumber + " (" + _controller.DocumentIndex + "/" + _controller.DocumentCount + ")";
        }

        #endregion        
    }
}